/*
 * DrawingPanel.java
 *
 * Created on September 15, 2008, 12:56 PM
 */
package gui;

import application.IAppContext;
import drawing.IDrawingManager;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import parser.ISequenceParserManager;

/**
 *
 * @author  kamlesh paunikar
 */
public class DrawingPanel extends javax.swing.JPanel {

    private String instructions;
    private IAppContext appContext;

    /** Creates new form DrawingPanel */
    public DrawingPanel(IAppContext appContext) {
        this.appContext = appContext;
        initComponents();
    }

    void draw(String instructions) {
        this.instructions = instructions;
        repaint();
    }

    @Override
    public void paint(Graphics graphics) {
        super.paint(graphics);
        Graphics2D graphics2D = (Graphics2D) graphics;
        if (instructions != null) {
            ISequenceParserManager sequenceParserManager = appContext.getSequenceParserManager();
            IDrawingManager drawingManager = appContext.getDrawingManager();
            drawingManager.reset();
            drawingManager.setGraphics(graphics);
            sequenceParserManager.parse(instructions);
            drawingManager.draw(graphics2D);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
